package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.TravelContentReply;
import cn.wolfcode.trip.base.mapper.TravelContentReplyMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ITravelContentReplyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TravelContentReplyImpl implements ITravelContentReplyService{
    @Autowired
    private TravelContentReplyMapper travelContentReplyMapper;

    public void saveReply(TravelContentReply travelContentReply) {
        travelContentReply.setCreateTime(new Date());
        travelContentReply.setState(0);
        travelContentReply.setTravel(travelContentReply.getTravel());
        travelContentReplyMapper.insert(travelContentReply);
    }

    public PageInfo getReplies(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<TravelContentReply>travelContentReplies= travelContentReplyMapper.selectReplies(qo);
        return new PageInfo(travelContentReplies);
    }

    public int getCommentNum(Long travelId) {
        return travelContentReplyMapper.getCommentNum(travelId);
    }
}
